//
//  MeatMarketsBannerTableViewCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/7/16.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatMarketsBannerTableViewCell.h"
#import "TJBannerView.h"
#import "JhPageItemView.h"
#import "BuyMeatModel.h"


@interface MeatMarketsBannerTableViewCell()<XXTGBannerDelegate, JhPageItemViewDelegate>


/**
 轮播图
 */
@property (nonatomic, strong) TJBannerView *bannerView;


/**
 Icon List View
 */
@property (nonatomic, strong) JhPageItemView *pageItemView;

@end

@implementation MeatMarketsBannerTableViewCell

#pragma mark - lifecycle methods

- (void)setupUI{
    
    self.backgroundColor = mBackgroudColor;
    
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.fillColor = KWhiteColor.CGColor;
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, KScreenWidth, 200)];
    layer.path = path.CGPath;
    [self.layer insertSublayer:layer atIndex:0];
    
    [self addSubview:self.bannerView];

}


#pragma mark - TJBannerView.delegate methods

- (void)banber:(TJBannerView *)bannerView clickedBannerIndex:(NSInteger)index
{
    if (self.dealBannerBlock) {
        self.dealBannerBlock(index);
    }
}


#pragma mark - JhPageItemView.delegate methods

- (void)JhPageItemViewDelegate:(JhPageItemView *)JhPageItemViewDeleagte indexPath:(NSIndexPath * )indexPath{
        
    if (self.dealItemBlock) {
        self.dealItemBlock(indexPath.item);
    }
}


- (void)setList:(NSArray<BuyMeatadvertiseModel *> *)list
{
    _list = list;
    NSMutableArray *aims = [NSMutableArray array];
    [list enumerateObjectsUsingBlock:^(BuyMeatadvertiseModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [aims addObject:obj.imgName];
    }];
    _bannerView.imageArray = [aims copy];;
}


- (void)setPigPartsArray:(NSArray *)myArray{
    
    _pigPartsArray = myArray;
    
    NSInteger row = myArray.count >5 ?2 : 1;
    CGFloat height = myArray.count >5 ?207 : 117;
    CGFloat gap = (KScreenWidth - 30 - 48*5)/5.0;
    
    CGRect frame =  CGRectMake(0, 0, KScreenWidth, height);
    
    JhPageItemView *pageItemView =  [[JhPageItemView alloc]initWithFrame:frame withmaxColumn:5 maxRow:row];
    pageItemView.backgroundColor = KWhiteColor;
    pageItemView.kTopBottomMargin = 15;
    pageItemView.kLeftRightMargin = 15;
    pageItemView.itemHorizontalMargin = gap;
    pageItemView.itemVerticalMargin = 20.f;
    pageItemView.current_BGColor = UIColorFromRGB(0x53C203);
    pageItemView.other_BGColor = UIColorFromRGB(0xE6E6E6);
    pageItemView.layoutStyle = JhCustomHorizontalArrangement;
    pageItemView.delegate = self;
    pageItemView.PageControlStyle = JhPageControlStyelRectangle;//长条样式
    pageItemView.PageControlContentMode = JhPageControlContentModeCenter;
    pageItemView.mj_y = self.bannerView.bottom;
    pageItemView.dataArray = myArray;

    [self addSubview:pageItemView];
}


#pragma mark - getter methods

- (TJBannerView *)bannerView
{
    if (!_bannerView) {
        _bannerView = [[TJBannerView alloc] init];
        _bannerView.frame = CGRectMake(15, 15, KScreenWidth - 30, 140);
        _bannerView.delegate = self;
    }
    return _bannerView;
}

@end
